//
// Copyright (C) 2011 - 2013  Steve Channell steve.channell@cepheis.com
//
// This file is part of Cephei.QL, an open-source library wrapper 
// arround QuantLib http://quantlib.org/
//
// Cephei.QL is open source software: you can redistribute it and/or modify it
// under the terms of the license.  You should have received a
// copy of the license along with this program; if not, please email
// <support@cepheis.com>. The license is also available online at
// <http://cepheis.com/license.htm>.
//
// This program is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
// FOR A PARTICULAR PURPOSE.  See the license for more details.
//
// Version 2.2 with QuantLib 1.2.1
//#include "stdafx.h"
#include "BoundedDomain.h"
using namespace Cephei::QL::Math;
#include <gen/QL/Math/Domain.h>
#undef HANDLE
#define ABSTRACT
#undef STRUCT
Cephei::QL::Math::CBoundedDomain::CBoundedDomain (boost::shared_ptr<QuantLib::BoundedDomain>& childNative, Object^ owner) : CDomain(CBoundedDomain::typeid)
{
#ifdef HANDLE
	_phBoundedDomain = NULL;
#endif
	_ppBoundedDomain = &childNative;
    _ppDomain = new boost::shared_ptr<QuantLib::Domain> (boost::dynamic_pointer_cast<QuantLib::Domain> (*_ppBoundedDomain));
}
Cephei::QL::Math::CBoundedDomain::CBoundedDomain (QuantLib::BoundedDomain& childNative, Object^ owner) : CDomain(CBoundedDomain::typeid)
{
#ifdef HANDLE
	_phBoundedDomain = NULL;
#endif
	_ppBoundedDomain = new boost::shared_ptr<QuantLib::BoundedDomain> (&childNative);
    _ppDomain = new boost::shared_ptr<QuantLib::Domain> (boost::dynamic_pointer_cast<QuantLib::Domain> (*_ppBoundedDomain));
    _BoundedDomainOwner = owner;
    _DomainOwner = owner;
}

Cephei::QL::Math::CBoundedDomain::CBoundedDomain (CBoundedDomain^ copy) : CDomain(CBoundedDomain::typeid)
{
#ifdef HANDLE
	_phBoundedDomain = NULL;
#endif
	if (copy->HasNative() != NULL)
    {
		_ppBoundedDomain = new boost::shared_ptr<QuantLib::BoundedDomain> (copy->GetShared());
        _ppDomain = new boost::shared_ptr<QuantLib::Domain> (boost::dynamic_pointer_cast<QuantLib::Domain> (*_ppBoundedDomain));
    }
}
Cephei::QL::Math::CBoundedDomain::CBoundedDomain (PLATFORM::Type^ t) : CDomain(CBoundedDomain::typeid)
{
#ifdef HANDLE
	_phBoundedDomain = NULL;
#endif
	if (!t->IsSubclassOf(CBoundedDomain::typeid))
		throw REFNEW Exception ("Invalid base-case init");
}
#ifdef HANDLE
Cephei::QL::Math::CBoundedDomain::CBoundedDomain (QuantLib::Handle<QuantLib::BoundedDomain>& childNative, Object^ owner)  : CDomain(CBoundedDomain::typeid)
{
	_phBoundedDomain = &childNative;
	_ppBoundedDomain = &static_cast<boost::shared_ptr<QuantLib::BoundedDomain>>(childNative.currentLink());
    _ppDomain = new boost::shared_ptr<QuantLib::Domain> (boost::dynamic_pointer_cast<QuantLib::Domain> (*_ppBoundedDomain));
    _BoundedDomainOwner = owner;
}
Cephei::QL::Math::CBoundedDomain::CBoundedDomain (QuantLib::Handle<QuantLib::BoundedDomain> childNative)  : CDomain(CBoundedDomain::typeid)
{
	_phBoundedDomain = &childNative;
	_ppBoundedDomain = &static_cast<boost::shared_ptr<QuantLib::BoundedDomain>>(childNative.currentLink());
    _ppDomain = new boost::shared_ptr<QuantLib::Domain> (boost::dynamic_pointer_cast<QuantLib::Domain> (*_ppBoundedDomain));
}
#endif
#ifdef STRUCT
Cephei::QL::Math::CBoundedDomain::CBoundedDomain (QuantLib::BoundedDomain childNative)  : CDomain(CBoundedDomain::typeid)
{
#ifdef HANDLE
	_phBoundedDomain = NULL;
#endif
	_ppBoundedDomain = new boost::shared_ptr<QuantLib::BoundedDomain> (new QuantLib::BoundedDomain (childNative));
    _ppDomain = new boost::shared_ptr<QuantLib::Domain> (boost::dynamic_pointer_cast<QuantLib::Domain> (*_ppBoundedDomain));
}
#endif

Cephei::QL::Math::CBoundedDomain::~CBoundedDomain ()
{
    if (_ppBoundedDomain != NULL)
    {
	    delete _ppBoundedDomain;
        _ppBoundedDomain = NULL;
    }
}
Cephei::QL::Math::CBoundedDomain::!CBoundedDomain ()
{
    if (_ppBoundedDomain != NULL)
    {
	    delete _ppBoundedDomain;
    }
}
QuantLib::BoundedDomain& Cephei::QL::Math::CBoundedDomain::GetReference ()
{
    if (_ppBoundedDomain == NULL) throw REFNEW NativeNullException ();
	return **_ppBoundedDomain;
}
boost::shared_ptr<QuantLib::BoundedDomain>& Cephei::QL::Math::CBoundedDomain::GetShared ()
{
    if (_ppBoundedDomain == NULL) throw REFNEW NativeNullException ();
	return *_ppBoundedDomain;
}
QuantLib::BoundedDomain* Cephei::QL::Math::CBoundedDomain::GetPointer ()
{
    if (_ppBoundedDomain == NULL) throw REFNEW NativeNullException ();
	return &**_ppBoundedDomain;
}
#ifdef HANDLE
QuantLib::Handle<QuantLib::BoundedDomain>& Cephei::QL::Math::CBoundedDomain::GetHandle ()
{
	if (_phBoundedDomain == NULL)
	{
		_phBoundedDomain = new Handle<QuantLib::BoundedDomain> (*_ppBoundedDomain);
	}
	return *_phBoundedDomain;
}
#endif
bool Cephei::QL::Math::CBoundedDomain::HasNative () 
{
	return (_ppBoundedDomain != NULL);
}

Double Cephei::QL::Math::CBoundedDomain::XLowerBound::get ()
{
    try
    {
    	QuantLib::Real _rv = (QuantLib::Real)(*_ppBoundedDomain)->xLowerBound ( );   
        Double _nrv = (Double)ValueHelper::Convert (_rv); //c
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Double Cephei::QL::Math::CBoundedDomain::XUpperBound::get ()
{
    try
    {
    	QuantLib::Real _rv = (QuantLib::Real)(*_ppBoundedDomain)->xUpperBound ( );   
        Double _nrv = (Double)ValueHelper::Convert (_rv); //c
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Double Cephei::QL::Math::CBoundedDomain::YLowerBound::get ()
{
    try
    {
    	QuantLib::Real _rv = (QuantLib::Real)(*_ppBoundedDomain)->yLowerBound ( );   
        Double _nrv = (Double)ValueHelper::Convert (_rv); //c
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Double Cephei::QL::Math::CBoundedDomain::YUpperBound::get ()
{
    try
    {
    	QuantLib::Real _rv = (QuantLib::Real)(*_ppBoundedDomain)->yUpperBound ( );   
        Double _nrv = (Double)ValueHelper::Convert (_rv); //c
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
    }
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Factory class

